package auto.feature;

import auto.device.Phione;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.PointerInput;
import org.openqa.selenium.interactions.Sequence;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import java.util.Collections;
import java.util.List;

//此处处理的的是群聊中的转发消息
public class GroupForwardMessage {

//feature1：在群聊中转发不同类型的消息
    public String forwardMessage() throws InterruptedException{
        Phione phione = new Phione();
        AppiumDriver driver = phione.driver;
        WebDriverWait wait = phione.wait;

        //发送文本消息并转发这个文本消息
        forwardTextMessage(driver,wait);

        //发送图片消息并转发这个图片消息
        forwardPictureMessage(driver,wait);

        //发送视频消息并转发视频这个视频消息
        forwardVideoMessage(driver,wait);

        //发送文件消息并转发这个文件消息
        forwardFileMessage(driver,wait);
        return "群聊转发消息成功";
    }


//转发文本消息
    private void forwardTextMessage(AppiumDriver driver,WebDriverWait wait) throws InterruptedException {
        //首先点击联系人，进入联系人列表
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain
                ("**/XCUIElementTypeButton[`name == \"联系人\"`]"))).click();

        //点击我的群组
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("我的群组"))).click();

        //选中第一个群聊
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

        //定位文本框元素
        WebElement textBox=wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("输入消息")));
        textBox.click();
        textBox.sendKeys("群聊转发测试文本消息");

        //点击发送按钮
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("MessagingApp.ConversationInputToolbar._sendButton"))).click();

        //定位发送的这条信息
        WebElement textMessage = wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain(
                "**/XCUIElementTypeOther[`name MATCHES '您发送： 群聊转发测试文本消息.*'`]")));

        //创建长按手势
        Actions actions = new Actions(driver);

        // 执行长按操作
        actions.clickAndHold(textMessage)
                .pause(Duration.ofSeconds(2))
                .release()
                .build()
                .perform();

        Thread.sleep(2000);

        //定位转发元素并点击
        try{
            wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("转发"))).click();
        }catch(TimeoutException e){
            System.out.println("发送时间过长");
            return;
        }

        //点击联系人进入页面选择一个联系人
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("联系人"))).click();

        //默认选择联系人中的第一个
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]" +
                "/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

        //选择之后会进入发送页面，点击出现的发送按钮
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("MessagingApp.ConversationInputToolbar._sendButton"))).click();

        //返回到主页面，方便下次点击我的群组选择群聊
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("icon back blue"))).click();
        System.out.println("转发文本消息成功");
    }

//转发图片消息
    private void forwardPictureMessage(AppiumDriver driver,WebDriverWait wait) throws InterruptedException{
        //首先点击联系人，进入联系人列表
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain
                ("**/XCUIElementTypeButton[`name == \"联系人\"`]"))).click();

        //点击我的群组
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("我的群组"))).click();

        //选中第一个群聊
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

        //点击附件按钮
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("MessagingApp.ConversationInputToolbar._attachmentButton"))).click();

        //上划列表
        WebElement element=wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("最近项目")));

        // 获取元素的位置和大小
        Point location = element.getLocation();
        Dimension size = element.getSize();

        // 计算长按的起始点和滑动的终止点
        int startX = location.getX() + size.getWidth() / 2;
        int startY = location.getY() + size.getHeight() / 2;
        int endY = startY - 200; // 向上滑动 200 像素

        // 创建 PointerInput 对象
        PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");

        // 创建 Sequence 对象
        Sequence sequence = new Sequence(finger, 1);

        // 添加动作到序列中
        sequence.addAction(finger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), startX, startY));
        sequence.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
        sequence.addAction(new org.openqa.selenium.interactions.Pause(finger, Duration.ofMillis(500)));
        sequence.addAction(finger.createPointerMove(Duration.ofMillis(500), PointerInput.Origin.viewport(), startX, endY));
        sequence.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));

        // 执行动作序列
        driver.perform(Collections.singletonList(sequence));

        //选中第一张图片
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[2]" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeCollectionView/XCUIElementTypeCell[2]/XCUIElementTypeOther/XCUIElementTypeButton"))).click();

        //选中之后添加说明
        WebElement textBox=wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain(
                "**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther" +
                        "/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeTextView")));
        textBox.click();
        textBox.sendKeys("群聊图片转发测试");

        //点击发送
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId( "input bar text nonempty"))).click();
        Thread.sleep(8000);

        //定位此图片进行长按操作
        WebElement PictureMessage = wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain(
                "**/XCUIElementTypeOther[`name MATCHES '您发送： 媒体, 群聊图片转发测试.*'`]")));

        //创建长按手势
        Actions actions = new Actions(driver);

        // 执行长按操作
        actions.clickAndHold(PictureMessage)
                .pause(Duration.ofSeconds(2))
                .release()
                .build()
                .perform();

        try{
            //定位转发元素并点击
            wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("转发"))).click();
        }catch(TimeoutException e){
            System.out.println("图片发送时间过长");
            return;
        }


        //点击联系人进入页面选择一个联系人
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("联系人"))).click();

        //默认选择联系人中的第一个
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]" +
                "/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

        //选择之后会进入发送页面，点击出现的发送按钮
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("MessagingApp.ConversationInputToolbar._sendButton"))).click();

        //返回到主页面，方便下次点击我的群组选择群聊
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("icon back blue"))).click();
        System.out.println("群聊转发图片消息成功");
    }

//转发视频消息
    private void forwardVideoMessage(AppiumDriver driver,WebDriverWait wait) throws InterruptedException{
        //首先点击联系人，进入联系人列表
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain
                ("**/XCUIElementTypeButton[`name == \"联系人\"`]"))).click();

        //点击我的群组
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("我的群组"))).click();

        //选中第一个群聊
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

        //点击附件按钮
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("MessagingApp.ConversationInputToolbar._attachmentButton"))).click();

        //上划列表
        WebElement element=wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("最近项目")));

        // 获取元素的位置和大小
        Point location = element.getLocation();
        Dimension size = element.getSize();

        // 计算长按的起始点和滑动的终止点
        int startX = location.getX() + size.getWidth() / 2;
        int startY = location.getY() + size.getHeight() / 2;
        int endY = startY - 200; // 向上滑动 200 像素

        // 创建 PointerInput 对象
        PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");

        // 创建 Sequence 对象
        Sequence sequence = new Sequence(finger, 1);

        // 添加动作到序列中
        sequence.addAction(finger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), startX, startY));
        sequence.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
        sequence.addAction(new org.openqa.selenium.interactions.Pause(finger, Duration.ofMillis(500)));
        sequence.addAction(finger.createPointerMove(Duration.ofMillis(500), PointerInput.Origin.viewport(), startX, endY));
        sequence.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));

        // 执行动作序列
        driver.perform(Collections.singletonList(sequence));

        //定位一个视频元素
        WebElement videoElement=wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("0:03")));

        System.out.println("开始获取父元素");
        //获取这个视频元素的父元素
        WebElement videoElementParent=driver.findElement(AppiumBy.xpath("//XCUIElementTypeAny[@name=\"0:03\"]/.."));

        System.out.println("开始查找叔叔元素");
        //获取videoElement父元素的同级别元素，并点击
        WebElement videoElementUncle =driver.findElement(AppiumBy.xpath("//XCUIElementTypeAny[@name=\"0:03\"]/../following-sibling::XCUIElementTypeButton | //XCUIElementTypeAny[@name=\"0:03\"]/../preceding-sibling::XCUIElementTypeButton"));
        videoElementUncle.click();

        //选中之后添加说明
        WebElement textBox=wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain(
                "**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther" +
                        "/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeTextView")));
        textBox.click();
        textBox.sendKeys("群聊视频转发测试");

        //点击发送
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId( "input bar text nonempty"))).click();
        Thread.sleep(8000);

        //定位此视频进行长按操作
        WebElement PictureMessage = wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain(
                "**/XCUIElementTypeOther[`name MATCHES '您发送： 媒体, 群聊视频转发测试.*'`]")));

        //创建长按手势
        Actions actions = new Actions(driver);

        // 执行长按操作
        actions.clickAndHold(PictureMessage)
                .pause(Duration.ofSeconds(2))
                .release()
                .build()
                .perform();

        try{
            //定位转发元素并点击
            wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("转发"))).click();
        }catch(TimeoutException e){
            System.out.println("视频发送时间过长");
            return;
        }


        //点击联系人进入页面选择一个联系人
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("联系人"))).click();

        //默认选择联系人中的第一个
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]" +
                "/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

        //选择之后会进入发送页面，点击出现的发送按钮
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("MessagingApp.ConversationInputToolbar._sendButton"))).click();

        //返回到主页面，方便下次点击我的群组选择群聊
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("icon back blue"))).click();
        System.out.println("群聊转发视频消息成功");
    }


//转发文件消息
    private void forwardFileMessage(AppiumDriver driver,WebDriverWait wait) throws InterruptedException{
        //首先点击联系人，进入联系人列表
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain
                ("**/XCUIElementTypeButton[`name == \"联系人\"`]"))).click();

        //点击我的群组
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("我的群组"))).click();

        //选中第一个群聊
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

        //点击附件按钮
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("MessagingApp.ConversationInputToolbar._attachmentButton"))).click();

        //点击文件
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("文件"))).click();

        //选择文件内文件
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("从文件中选择"))).click();

        //点击直接发送
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("专门用来测试的文件"))).click();
        Thread.sleep(5000);

        //定位此视频进行长按操作
        List<WebElement> fileMessages=driver.findElements(AppiumBy.iOSClassChain("**/XCUIElementTypeOther[`name MATCHES '您发送： 附件.*'`]"));

        WebElement newFileMessage=fileMessages.get(fileMessages.size()-1);
        //创建长按手势
        Actions actions = new Actions(driver);

        // 执行长按操作
        actions.clickAndHold(newFileMessage)
                .pause(Duration.ofSeconds(2))
                .release()
                .build()
                .perform();

        try{
            //定位转发元素并点击
            wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("转发"))).click();
        }catch(TimeoutException e){
            System.out.println("文件发送时间过长");
            return;
        }


        //点击联系人进入页面选择一个联系人
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("联系人"))).click();

        //默认选择联系人中的第一个
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]" +
                "/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

        //选择之后会进入发送页面，点击出现的发送按钮
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("MessagingApp.ConversationInputToolbar._sendButton"))).click();

        //最后点击返回到主页面
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("icon back blue"))).click();
        System.out.println("群聊转发文件消息成功");
    }





//feature2：批量转发群消息
    public String forwardLotMessages(){
    Phione phione = new Phione();
    AppiumDriver driver = phione.driver;
    WebDriverWait wait = phione.wait;

    //首先点击联系人，进入联系人列表
    wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain
            ("**/XCUIElementTypeButton[`name == \"联系人\"`]"))).click();

    //点击我的群组
    wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("我的群组"))).click();

    //选中第一个群聊
    wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther" +
            "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther" +
            "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

    //首先任意识别一个消息，进行长按操作
    List<WebElement> messagesList=driver.findElements(AppiumBy.iOSClassChain("**/XCUIElementTypeOther[`name CONTAINS '发送'`]"));

    //长按第一个，出现选择就行
    WebElement secondMessage=messagesList.get(1);
    //创建长按手势
    Actions actions = new Actions(driver);

    // 执行长按操作
    actions.clickAndHold(secondMessage)
            .pause(Duration.ofSeconds(2))
            .release()
            .build()
            .perform();

    //定位选择元素并点击
    wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("选择"))).click();

    //点击选择后开始对消息前面出现的选择框选中
    List<WebElement> selectBoxList = driver.findElements(AppiumBy.iOSClassChain("**/XCUIElementTypeCollectionView[`name == 'collectionView'`]" +
            "/XCUIElementTypeCell[*]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeOther" +
            "/XCUIElementTypeImage"));

    int i=2;
    for(;i<selectBoxList.size();i++){
        selectBoxList.get(i).click();
    }

    //点击下方的批量发送按钮
    wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain
            ("**/XCUIElementTypeToolbar[`name == \"Toolbar\"`]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeButton[5]"))).click();

    //点击联系人进入页面选择一个联系人
    wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("联系人"))).click();

    //默认选择联系人中的第一个
    wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]" +
            "/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther" +
            "/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

    //选择之后会进入发送页面，点击出现的发送按钮
    wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("MessagingApp.ConversationInputToolbar._sendButton"))).click();

    //最后点击返回到主页面
    wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("icon back blue"))).click();
    System.out.println("群聊消息批量转发成功");
    return "群聊批量转发消息成功";
}



//feature3:转发大型文件
    public String forwardBigFile(){
        Phione phione = new Phione();
        AppiumDriver driver = phione.driver;
        WebDriverWait wait = phione.wait;

        //首先点击联系人，进入联系人列表
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain
                ("**/XCUIElementTypeButton[`name == \"联系人\"`]"))).click();

        //点击我的群组
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("我的群组"))).click();

        //选中第一个群聊
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();
        //定位刚才发送的大型文件
        List<WebElement> fileMessages=driver.findElements(AppiumBy.iOSClassChain("**/XCUIElementTypeOther[`name MATCHES '您发送： 附件.*'`]"));

        WebElement newFileMessage=fileMessages.get(fileMessages.size()-1);
        //创建长按手势
        Actions actions = new Actions(driver);

        // 执行长按操作
        actions.clickAndHold(newFileMessage)
                .pause(Duration.ofSeconds(2))
                .release()
                .build()
                .perform();


        //点击出现的长按
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("转发"))).click();

        //点击联系人进入页面选择一个联系人
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("联系人"))).click();

        //默认选择联系人中的第一个
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]" +
                "/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther" +
                "/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeTable/XCUIElementTypeCell[1]"))).click();

        //选择之后会进入发送页面，点击出现的发送按钮
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("MessagingApp.ConversationInputToolbar._sendButton"))).click();

        //最后点击返回到主页面
        wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("icon back blue"))).click();
        System.out.println("转发大型文件成功");
        return "已转发大型文件";
    }

}
